package wwl.lsf.springmvc;

import java.io.File;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import wwl.lsf.AppConfig;

public class MySringApplication {

  public static void run() throws LifecycleException {

//    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
//    webApplicationContext.register(AppConfig.class);
//    webApplicationContext.refresh();

    Tomcat tomcat = new Tomcat();
    tomcat.setPort(9080);
    String property = System.getProperty("java.io.tmpdir");
    File file = new File(property);
    System.out.println("property ============= " + property);
//    Context context = tomcat.addContext("/", file.getAbsolutePath());
    Context context = tomcat.addContext("/", new File("src/main/webapp").getAbsolutePath());
//    DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
//    tomcat.addServlet(context,"wwlMVC",dispatcherServlet).setLoadOnStartup(1);
    context.addServletMappingDecoded("/","wwlMVC");
    tomcat.start();
    tomcat.getServer().await();

  }

  public static void main(String[] args) throws LifecycleException {
    run();
  }

}
